package ca.cbc.localsrvextadmin.converter;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import ca.cbc.giscommon.dao.EventSubcategoryDAO;
import ca.cbc.giscommon.entity.EventSubcategory;

public class EventSubcategoryConverter extends StrutsTypeConverter {
	
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		EventSubcategory c = null;
        if (values != null && values.length > 0 && values[0] != null && values[0].length() > 0) {
        	String id = values[0];
        	c = new EventSubcategoryDAO().findById(Long.valueOf(id));
        }
		return c;
	}

	@Override
	public String convertToString(Map context, Object o) {
		if (o instanceof EventSubcategory) {
			return ((EventSubcategory) o).getSubcategory();
		}
		return null;
	}
}
